<template>
  <div class="person">
    <h2>当前求和：{{sum}}</h2>
    <button @click="changeSum">sum+1</button>
  </div>
</template>

<script setup lang="ts" name="Person">
import {ref,watch} from 'vue'

let sum = ref(0)

function changeSum() {
  sum.value += 1
}

let x = watch(sum, (newVal, oldVal) => {
  console.log('sum变化了',newVal, oldVal);
  if (newVal >= 10) {
    x();
  }
})
console.log(x);

</script>

<style scoped>
  .person {
    padding: 10px;
    box-shadow: 0 0 10px;
    background: #ccc;
  }
  li {
    font-size: 20px;
  }
</style>